<?php
namespace app\admin\controller;
use app\service\adminService;
use think\Db;
use think\Controller;
use app\service\deviceService;
use app\service\wotuService;
use app\service\iotmcuService;
ini_set('max_execution_time','0');
class Test extends Controller
{
    public function yzl7(){

        $url = "http://192.168.31.25:8090/setWeigenContent";
        $pass = "202188";
        $recSucWiegandType="3";
        $recSucWiegandContent = "00023";


        $data = ['pass'=>$pass,'recSucWiegandType'=>$recSucWiegandType,'recSucWiegandContent'=>$recSucWiegandContent];
        $headers =array('Content-Type: application/x-www-form-urlencoded');
        $curl = curl_init();// 启动一个CURL会话
        curl_setopt($curl, CURLOPT_URL,$url);// 要访问的地址
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);// 对认证证书来源的检查
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);// 从证书中检查SSL加密算法是否存在
        curl_setopt($curl, CURLOPT_USERAGENT,$_SERVER['HTTP_USER_AGENT']);// 模拟用户使用的浏览器
        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);// 使用自动跳转
        curl_setopt($curl, CURLOPT_AUTOREFERER, 1);// 自动设置Referer
        curl_setopt($curl, CURLOPT_POST, 1);// 发送一个常规的Post请求
        curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));// Post提交的数据包
        curl_setopt($curl, CURLOPT_TIMEOUT, 30);// 设置超时限制防止死循环
        curl_setopt($curl, CURLOPT_HEADER, 0);// 显示返回的Header区域内容
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);// 获取的信息以文件流的形式返回
        curl_setopt($curl, CURLOPT_HTTPHEADER,$headers);
        $result = curl_exec($curl);// 执行操作
        if (curl_errno($curl)) {
            echo 'Errno'.curl_error($curl);//捕抓异常
        }
        curl_close($curl);// 关闭CURL会话
        var_dump($result);
    }
	public function yzl3(){
       $a="1501";
       $b=substr($a,0,2);
       echo $a.$b;
	}
	
	public function test(){
		$userlist=Db::table("personnel")->where("building",6)->where("unit",1)->order('id')->select();
		
		

		foreach ($userlist as $key => $userinfo) {
			if($userinfo["personGuid"]!="0"){
				 //小区大门
		        $locklist1= $locklist=Db::table("device")->where("devicetype",1)->select();
		        
		        $locklist2= Db::table("device")
		                        ->where("devicetype",2)
		                        ->where("building",$userinfo["building"])
		                        ->where("unit",$userinfo["unit"])
		                        ->select();
		        $locklist=array_merge($locklist1,$locklist2);
		        $deviceKeys="";
		        foreach ($locklist as $key => $value) {
		            $deviceKeys=$deviceKeys.$value["devicekey"].",";
		        }
		        $deviceKeys=rtrim($deviceKeys,",");
		        $res=(new wotuService())->accredit($userinfo["personGuid"], $deviceKeys);
		        var_dump($res);echo $userinfo["id"];echo "<br/>";
			}
			
			
	        
		}
		/*
		//查询该小区下的人脸设备并授权
        $locklist=(new deviceService())->userdeviceList($user_id);
        $deviceKeys="";
        if(empty($locklist)){
            return json(["errCode"=>"0",'msg' =>"图片上传成功"]); 
        }
       
        $deviceKeys=rtrim($deviceKeys,",");
        (new wotuService())->accredit($guid, $deviceKeys);*/
	}

	public function test2(){
		//$userlist=Db::table("personnel")->order('id')->limit(500)->select();
		$userlist=Db::table("personnel")->order('id')->limit(500,1000)->select();
		var_dump($userlist);die;
		//$userlist=Db::table("personnel")->order('id')->limit(1000,1500)->select();
		//$userlist=Db::table("personnel")->order('id')->limit(1500,2000)->select();
		//$userlist=Db::table("personnel")->order('id')->limit(2000,2500)->select();
		//$userlist=Db::table("personnel")->order('id')->limit(2500,3000)->select();
		//$userlist=Db::table("personnel")->order('id')->limit(3000,3500)->select();
		//$userlist=Db::table("personnel")->order('id')->limit(4000,4500)->select();
		foreach ($userlist as $key => $userinfo) {
			echo $userinfo["id"];echo "<br/>";
		}
	}
	public function test3(){
		$userlist=Db::table("personnel")->order('id')->limit(1500,100)->select();
		echo "<pre>";
		var_dump($userlist);die;
		foreach ($userlist as $key => $userinfo) {
			if($userinfo["personGuid"]!="0"){
				 //小区大门
		        $locklist1= $locklist=Db::table("device")->where("devicetype",1)->select();
		        
		        $locklist2= Db::table("device")
		                        ->where("devicetype",2)
		                        ->where("building",$userinfo["building"])
		                        ->where("unit",$userinfo["unit"])
		                        ->select();
		        $locklist=array_merge($locklist1,$locklist2);
		        $deviceKeys="";
		        foreach ($locklist as $key => $value) {
		            $deviceKeys=$deviceKeys.$value["devicekey"].",";
		        }
		        $deviceKeys=rtrim($deviceKeys,",");
		        $res=(new wotuService())->accredit($userinfo["personGuid"], $deviceKeys);
		        var_dump($res);echo $userinfo["id"];echo "<br/>";
			}
			
			
	        
		}
	}
}
